#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

int g_val=100;

int main(){
  pid_t id=fork();
  if(id==0){
    //child
    int cnt=5;
    while(1){
      printf("child:pid=%d,ppid=%d,g_val=%d,addr=%p\n",getpid(),getppid(),g_val,&g_val);
      sleep(1);
      if(cnt--==0){
        g_val=200;
        printf("child: change g_val to 200\n");
      }
    }
  }else{
    //parent
    while(1){
      printf("parent:pid=%d,ppid=%d,g_val=%d,addr=%p\n",getpid(),getppid(),g_val,&g_val);
      sleep(1);
    }
  }
}
